package com.woniuxy.microgoodsserver.auctionmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microgoodsserver.auctionmag.mapper.GoodsBrandMapper;
import com.woniuxy.microgoodsserver.auctionmag.mapper.GoodsUnitMapper;
import com.woniuxy.microgoodsserver.auctionmag.service.GoodsBrandService;
import com.woniuxy.microgoodsserver.auctionmag.service.GoodsUnitService;
import com.woniuxy.microgoodsserver.bean.GoodsBrandBean;
import com.woniuxy.microgoodsserver.bean.GoodsSortBean;
import com.woniuxy.microgoodsserver.bean.GoodsUnitBean;
import com.woniuxy.microgoodsserver.bean.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsUnitServiceImpl implements GoodsUnitService {

    @Resource
    GoodsUnitMapper goodsUnitMapper;

    @Override
    public PageInfo<GoodsUnitBean> unitFindAll(PageRequest pageRequest, GoodsUnitBean goodsUnitBean) {
        List<GoodsUnitBean> goodsUnitBeans = goodsUnitMapper.unitFindAll(pageRequest,goodsUnitBean);
        return PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getLimit()).
                doSelectPageInfo(()->goodsUnitMapper.unitFindAll(pageRequest,goodsUnitBean));

    }

    @Override
    public GoodsUnitBean unitFindById(int id) {
        GoodsUnitBean goodsUnitBean = goodsUnitMapper.unitFindAllById(id);
        return goodsUnitBean;
    }

    @Override
    public int savaUnit(GoodsUnitBean goodsUnitBean) {
        int a = goodsUnitMapper.SaveUnit(goodsUnitBean);
        return a;
    }

    @Override
    public int updateUnit(GoodsUnitBean goodsUnitBean) {
        int a = goodsUnitMapper.updateGoodUnitBean(goodsUnitBean);
        return a;
    }
}
